package licode.unisop.single.user.infrastructure.repository.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import licode.unisop.single.user.application.entity.ProviderEntity;
import licode.unisop.single.user.application.gateway.ProviderDao;
import licode.unisop.single.user.infrastructure.assembler.UniUserSingleAssembler;
import licode.unisop.single.user.infrastructure.repository.mapper.ProviderMapper;
import licode.unisop.single.user.infrastructure.repository.po.ProviderPO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * uni-user-single
 *
 * @author licode
 * @date 2016-01-14 12:23:32
 */
@Component
public class ProviderDaoImpl
        extends ServiceImpl<ProviderMapper, ProviderPO>
        implements ProviderDao {
    @Resource
    private UniUserSingleAssembler uniUserSingleAssembler;

    @Override
    public void add(ProviderEntity item) {
        super.save(uniUserSingleAssembler.fromProviderEntity(item));
    }

    @Override
    public void update(ProviderEntity item) {
        super.updateById(uniUserSingleAssembler.fromProviderEntity(item));
    }

    @Override
    public void removeWithId(Serializable id) {
        super.removeById(id);
    }

    @Override
    public ProviderEntity getWithId(Serializable id) {
        return uniUserSingleAssembler.fromProvider(super.getById(id));
    }

    @Override
    public List<ProviderEntity> getList() {
        return uniUserSingleAssembler.fromProvider(super.lambdaQuery()
                .eq(ProviderPO::getType, "REALM")
                .list());
    }
}
